//
// Created by 12992 on 24-10-13.
//

#ifndef FRAME_COUNTER_ERROR_HPP
#define FRAME_COUNTER_ERROR_HPP

#include <stdexcept>
#include <string>
extern "C" {
#include <libavutil/error.h>
}

namespace error
{
    class video_meta_error final
            : public std::runtime_error
    {
    public:
        enum class type
        {
            PATH_ERROR,
            FILE_OPEN_ERROR,
            FIND_STREAM_ERROR,
            PACKET_ALLOC_ERROR,
            READ_FRAME_ERROR,
            SEEK_FRAME_ERROR,
            DECODER_NOT_FOUND,
            CODER_CTX_ALLOC_ERROR,
            CODER_CTX_SET_ERROR,
            CODER_OPEN_ERROR,
            DECODE_ERROR,
            SCALE_ERROR,
            UNKNOWN_ERROR,
        };

        video_meta_error(type _type, int error_code)
                : runtime_error(""),
                  m_type(_type), m_error_code(error_code)
        {
            char buffer[64]{};
            av_make_error_string(buffer, sizeof(buffer), error_code);
            this->m_msg = buffer;
        }

        video_meta_error(type _type, std::string msg, int error_code = -1)
                : runtime_error(""), m_type(_type), m_error_code(error_code), m_msg(std::move(msg))
        {
        }

        ~video_meta_error() override = default;

        [[nodiscard]] const char* what() const noexcept override
        {
            return this->m_msg.c_str();
        }


        type get_type() const { return this->m_type; }

        int error_code() const { return this->m_error_code; }

    private:
        type m_type;
        int m_error_code;
        std::string m_msg;
    };
}

#endif //FRAME_COUNTER_ERROR_HPP
